/*
 * @(#)MaintUserRoleAction.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.user.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.Utility;
import com.dcivision.framework.web.AbstractActionForm;
import com.dcivision.user.bean.UserMember;
import com.dcivision.user.dao.UserRolePermissionDAObject;
import com.dcivision.workflow.dao.MtmWorkflowDynamicUserActorDAObject;
import com.dcivision.workflow.dao.MtmWorkflowStepUserActorDAObject;

/**
  MaintUserRoleAction.java

  This class is for maint user role.

    @author          Phoebe Wong
    @company         DCIVision Limited
    @creation date   24/07/2003
    @version         $Revision: 1.10 $
*/

/* ********************************Modify History***********************************************
 * Modify by  : Jicle.Wang 
 * Modify date: 2006/06/12
 * Description: Show data in .jsp to Copy
 * *********************************************************************************************
 */
 
public class MaintUserRoleAction extends AbstractFunctionAccessAction {

  public static final String REVISION = "$Revision: 1.10 $";

  public MaintUserRoleAction() {
    super();
  }

  /**
   * getMajorDAOClassName
   *
   * @return  The class name of the major DAObject will be used in this action.
   */
  public String getMajorDAOClassName() {
    return("com.dcivision.user.dao.UserRoleDAObject");
  }

  /**
   * getFunctionCode
   *
   * @return  The corresponding system function code of action.
   */
  public String getFunctionCode() {
    return(SystemFunctionConstant.SETUP_USER_ROLE);
  }

  /**
   * clearUniqueFields
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @throws ApplicationException
   */
/* Jicle.Wang 2006/06/12 Start */
  //public void clearUniqueFields(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    //MaintUserRoleForm userRoleForm = (MaintUserRoleForm)form;
    //userRoleForm.setRoleName(null);
  //}
/* Jicle.Wang 2006/06/12 End   */
  /**
   * selectRecord
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @throws ApplicationException
   */
  public void selectRecord(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    super.selectRecord(mapping, form, request, response);
    UserRolePermissionDAObject userRoleDAO = new UserRolePermissionDAObject(this.getSessionContainer(request), this.getConnection(request));
    List result = userRoleDAO.getListByUserRoleIDObjectType(new Integer(form.getID()), GlobalConstant.OBJECT_TYPE_FUNCTION);
    retrievePermission(form, result);
  }
  
  //simon_add_S
  public void deleteRecord(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {	
	MaintUserRoleForm userRoleForm = (MaintUserRoleForm)form;
	String SuserRoleID = userRoleForm.getID();		
	if (!Utility.isEmpty(SuserRoleID)){
	  Integer userRoleID = new Integer(SuserRoleID);
	  MtmWorkflowStepUserActorDAObject mtmWorkflowStepActorDAO=new MtmWorkflowStepUserActorDAObject(this.getSessionContainer(request), this.getConnection(request));
	  MtmWorkflowDynamicUserActorDAObject dynamicUserActorDAO=new MtmWorkflowDynamicUserActorDAObject(this.getSessionContainer(request), this.getConnection(request));
	  List userRoleList=mtmWorkflowStepActorDAO.getListWorkflowStepIDByActorIDAndActorType(userRoleID,UserMember.MEMBER_TYPE_GROUP);
	  List dynamicUserRoleList=dynamicUserActorDAO.getListWorkflowStepIDByActorIDAndActorType(userRoleID,UserMember.MEMBER_TYPE_GROUP);
	  if (Utility.isEmpty(userRoleList) && Utility.isEmpty(dynamicUserRoleList)){
		super.deleteRecord(mapping, form, request, response);
	  }else{
	  	throw new ApplicationException("common.message.cannot_deleted_record_operation_aborted");
	  }
	}else{
  	  throw new ApplicationException("common.message.cannot_deleted_record_operation_aborted");
  	}
  }
  //simon_add_E
}
